/**
 *  @author :   JiGuangJie
 *  @date   :   2020/5/13
 *  @time   :   14:08
 *  @Email  :   530904731@qq.com
 */
let x = 150, y = 150;
let x1 = 10, y1 = 10;

const canvas = document.getElementById('canvas');
canvas.width = 500;
canvas.height = 500;
// let gl = canvas.getContext('webgl');
let gl = getWebGLContext(canvas);
// 指定清空canvas的颜色，也就是背景颜色0
gl.clearColor(0.0, 0.0, 0.0, 1.0);
// 设定canvas初始化时候的深度
gl.clearDepth(1.0);
// 清空canvas（清空的是颜色缓冲区）
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

const vshader = document.getElementById('vs').innerText;
const fshader = document.getElementById('fs').innerText;
if (!initShaders(gl, vshader, fshader)) {
    console.log('Failed to initialize shaders.');
}
let a_Position = gl.getAttribLocation(gl.program, 'a_Position');
let rect = canvas.getBoundingClientRect();

x = ((x - rect.left) - canvas.height * 0.5) / canvas.height * 0.5;
y = (canvas.width * 0.5 - (y - rect.top)) / canvas.width * 0.5;

x1 = ((x1 - rect.left) - canvas.height * 0.5) / canvas.height * 0.5;
y1 = (canvas.width * 0.5 - (y1 - rect.top)) / canvas.width * 0.5;
let aa = [[x, y], [x1, y1]];
// 将点的位置传递到变量a_Position中
for (let i = 0; i < 2; i++) {
    // const rectElement = rect[i];
    gl.vertexAttrib3f(a_Position, aa[i][0], aa[i][1], 0.0);
    gl.drawArrays(gl.POINTS, 0, 1);
}
